<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <button id='button'>add</button>
    <script>
        //弱引用
        // var button=document.getElementById('button')
        // wm=new WeakMap()

        // wm.set(button,{count:0})
        // function buttonClick(){
        //     var data=wm.get(button)
        //     data.count++
        //     console.log(data.count)
        // }

        // button.addEventListener('click',buttonClick)
        // button.removeEventListener('click',buttonClick)
        // button=null
        // console.log(wm.get(button))

        //私有变量
        var Stack=(function(){
            var vm=new WeakMap()
            return class{
                constructor(){
                    vm.set(this,[])
                }
                push(value){
                    vm.get(this).push(value)
                }
                pop(){
                    return vm.get(this).pop()
                }
                toString(){
                    console.log(vm.get(this)) 
                }
            }
        })()
        var stack=new Stack()
        stack.push(1)
        stack.push(2)
        console.log(stack)
        stack.toString()
    </script>
</body>
</html>